/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aljfce.business.utils;

import com.aljfce.business.entity.Event;
import java.util.Comparator;

/**
 *
 * @author Antonio
 */
public class EventComparator implements Comparator<Event> {
    /**
     * This method given two {@link Event} objects compares their starting dates.
     * @param e1 
     * @param e2
     * @return -1 if e1 event's starting date is before e2 event's starting date, 0 otherwise
     */
    @Override
    public int compare(Event e1, Event e2) {
        if(e1==null||e2==null)
            throw new IllegalArgumentException("Events cannot be null");
        if (e1.getStartingDate().compareTo(e2.getStartingDate()) < 0){
            return -1;
        } 
        else {
            if (e1.getStartingDate().compareTo(e2.getStartingDate()) > 0) {
                return 1;
            }
            else return 0;
        }
    }    
}
